ARG BUILDPLATFORM=${BUILDPLATFORM:-amd64}
FROM --platform=${BUILDPLATFORM} node:20-alpine AS nantianmen-node

ARG NPM_BUILD_CMD = "build"

RUN apt-get update -qq \    
    && apt-get install -yqq --no-install-recommands \
        build-essential

RUN npm install -g pnpm

WORKDIR /build

RUN --mount=type=bind,target=./packages/client/package.json,src=./packages/client/package.json \
    --mount=type=bind,target=./packages/nantianmen/packages.json,src=./packages/nantianmen/package.json \
    --mount=type=bind,target=./package.json,src=./package.json \
    --mount=type=bind,target=./pnpm-lock.yaml,src=./pnpm-lock.yaml \
    --mount=type=bind,target=./pnpm-workspace.yaml,src=./pnpm-workspace.yaml \
    pnpm install -r

COPY ./packages ./
RUN pnpm -c ./packages/nantianmen run build
